package com.csu.cphone.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.csu.common.utils.PasswdUtil;
import com.csu.cphone.dao.ProducerMapper;
import com.csu.cphone.pojo.ProducerPojo;
import com.csu.cphone.service.ProducerService;

/**
 * @项目名称：cphone
 * @类名称：ProducerServiceImpl
 * @类描述：
 * @创建人：Tangc
 * @创建时间：2017年12月5日 下午9:15:30
 * @company:
 */
@Service
public class ProducerServiceImpl implements ProducerService
{

    @Autowired
    private ProducerMapper producerMapper;

    /**
     * @see com.csu.cphone.service.ProducerService#add(java.lang.String,
     *      java.lang.String, java.lang.String, java.lang.String,
     *      java.lang.String)
     */
    @Override
    public ProducerPojo add(String number, Integer role, Integer bussiness, String name, String passwd)
    {
        String passwordMd5 = PasswdUtil.md5Passwd(passwd);
        ProducerPojo producer = new ProducerPojo();
        producer.setName(name);
        producer.setNumber(number);
        producer.setPasswd(passwordMd5);
        producer.setBussiness(bussiness);
        producer.setRole(role);
        producerMapper.insert(producer);
        return producer;
    }

    /**
     * @see com.csu.cphone.service.ProducerService#update(com.csu.cphone.pojo.ProducerPojo)
     */
    @Override
    public Integer update(ProducerPojo producer)
    {
        String passwd = producer.getPasswd();
        if (passwd != null)
        {
            producer.setPasswd(PasswdUtil.md5Passwd(passwd));
        }

        return producerMapper.update(producer);
    }

    /**
     * @see com.csu.cphone.service.ProducerService#queryById(java.lang.Integer)
     */
    @Override
    public ProducerPojo queryById(Integer producerId)
    {
        return producerMapper.selectById(producerId);
    }

    /**
     * @see com.csu.cphone.service.ProducerService#count()
     */
    @Override
    public Integer count()
    {
        return producerMapper.count();
    }

    /**
     * @see com.csu.cphone.service.ProducerService#queryList(java.lang.Integer,
     *      java.lang.Integer, java.lang.String)
     */
    @Override
    public List<ProducerPojo> queryList(Integer pageSize, Integer startIndex, String order)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pageSize", pageSize);
        map.put("startIndex", startIndex);
        map.put("order", order);

        return producerMapper.queryList(map);
    }

    /**
     * @see com.csu.cphone.service.ProducerService#del(java.lang.Integer)
     */
    @Override
    public Integer deleteById(Integer producerId)
    {
        return producerMapper.deleteById(producerId);
    }

}
